#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int n = 0;
    cin >> n;
    vector<int> dp(n, 0);
    cin >> dp[0];
    int max = dp[0];
    int infer = 0;
    int tmp = 0;
    for (int i = 1;i < n;i++)
    {
        cin >> tmp;
        if (tmp > max)
        {
            infer = max;
            max = tmp;
        }
        else if (tmp > infer)
        {
            infer = tmp;
        }
        dp[i] = infer;
    }
    for (auto& a : dp)
    {
        cerr << a << " ";
    }
    cerr << endl;
    int q = 0;
    cin >> q;
    int x = 0;
    while (q--)
    {
        cin >> x;
        cout << dp[x - 1] << endl;
    }
    return 0;
}
